package com.ruoyi.celoan.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.celoan.entity.ExTradeEffectEnterprisesDetailEntity;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface ExTradeEffectEnterprisesDetailMapper extends BaseMapper<ExTradeEffectEnterprisesDetailEntity> {

    @Select("SELECT " +
            "    ei.id AS id, " +
            "    1306 AS platform_id, " +
            "    CASE WHEN ei.real_name_flag = '1' THEN '是' ELSE '否' END AS real_name_certification, " +
            "    0 AS is_flag, " +
            "    ei.enterprise_name AS enterprise_name, " +
            "    ei.credit_code AS unisc_id, " +
            "    ei.corr_address AS address, " +
            "    ei.province_name AS province, " +
            "    ei.city_name AS city, " +
            "    ei.area_name AS area, " +
            "    CAST(ei.registered_capital AS DECIMAL(19,2)) AS registered_capital, " +
            "    ei.business_scope AS business_scope, " +
            "    COALESCE(ei.business_term_type, 1) AS operating_time_limit_type, " +
            "    DATE_FORMAT(ei.business_term_start, '%Y-%m-%d') AS operating_time_limit_date_begin, " +
            "    DATE_FORMAT(ei.business_term_end, '%Y-%m-%d') AS operating_time_limit_date_end, " +
            "    DATE_FORMAT(ei.update_time, '%Y-%m-%d') AS approval_date, " +
            "    DATE_FORMAT(ei.create_time, '%Y-%m-%d %H:%i:%s') AS settling_time, " +
            "    ei.id AS external_system_id, " +
            "    COALESCE(ei.industry, 1) AS industry, " +
            "    ei.micro_flag AS xwqyflag, " +
            "    el.name AS operator_name, " +  // ✅ 用 MAX 包裹
            "    '法人' AS operator_identity, " +
            "    el.id_card AS operator_id_card_no, " +  // ✅ 用 MAX 包裹
            "    '是' AS loaned, " +
            "    '130400' AS area_code, " +
            "    CASE WHEN ei.enterprise_nature NOT IN ('3', '8', '9') THEN '是' ELSE '否' END AS is_private_enterprise " +
            "FROM ec_enterprise_information ei " +
            "INNER JOIN ec_enterprise_legal el ON ei.id = el.enterprise_id " +
            "LEFT JOIN ex_trade_effect_enterprises_detail cd ON cd.id = ei.id " +
            "WHERE DATE_FORMAT(ei.create_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m') " +
            "  AND ei.examine_result = 2 " +
            "  AND ei.registered_capital IS NOT NULL " +
            "  AND cd.id IS NULL ")
    List<ExTradeEffectEnterprisesDetailEntity> selectEnterpriseInfo();

}


/* Location:              D:\tuodayun\workspace\work\celoan-third-data-report-service-2.0.0-SNAPSHOT.jar!\BOOT-INF\classes\com\celoan\mapper\ExTradeEffectEnterprisesDetailMapper.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */
